#! /bin/bash

attack_times=10000
round_wait_time=50 # 20 min
wait_submit_time=31 # 20 s
log_file="logs"
run_time=3m
next_attack_time=0.5

log() {
    t=`date "+%H:%M:%S"`
    m="[$t]$m"
    info="\033[43;37m $m ]\033[0m"
    echo -e "$info"
    echo -e "\n$m" >> $log_file
}

attack() {
    echo "-- round $i -- " >> all_flags
    cat flags >> all_flags
    rm flags
    for line in `cat hosts`;do
        timeout --foreground $run_time python2 ./exp $line 2> /dev/null 2> /dev/null &
        sleep $next_attack_time
    done
    echo -e "\x1b[47;30m Waitting $wait_submit_time s to submit flag\x1b[0m"
    sleep $wait_submit_time
    echo -e "\x1b[47;30m Submiting flag\x1b[0m"
    ./submit_flag
}

for((i=1; i <= $attack_times; i++));
do
    m="-------- round $i --------"
    log $m
    attack
    echo -e "\x1b[47;30m Waitting next round\x1b[0m"
    sleep $round_wait_time
done
